import { takeLatest, put, all} from 'redux-saga/effects';

import axios from 'axios';

import { FETCH_HOME_MULTIDATA } from './constants';
import { changeBannerAction, changeRecommendAction } from './actionCreators';

function* fetchHomeMultidata(action) {
  console.log(action);
  const res = yield axios.get("http://123.207.32.32:8000/home/multidata");
  const { data } = res.data;
  console.log("redux-saga", data);
  // yield put(changeBannerAction(data.banner.list));
  // yield put(changeRecommendAction(data.recommend.list));
  yield all([
    yield put(changeBannerAction(data.banner.list)),
    yield put(changeRecommendAction(data.recommend.list))
  ])
}

function* mySaga() {
  // takeEvery：每一个都会被执行
  // takeLatest：只监听最后一次action
  yield takeLatest(FETCH_HOME_MULTIDATA, fetchHomeMultidata)

  // yield all([
  //   takeLatest(FETCH_HOME_MULTIDATA, fetchHomeMultidata),
  //   takeLatest(ADD_NUMBER, fetchHomeMultidata),
  // ]);
}

export default mySaga